<template>
	<view id="msginfo">
		<fu-navbar :title="groupInfo.name" bgColor="#fff"></fu-navbar>
		<view class="msginfo">
			<view class="msginfo_users flex-row flex">
				<!-- @tap="$api.navTo('/pages/chat_child/userInfo/userInfo?id='+item.userID)" -->
				<view class="msginfo_users_infoBox flex-col" v-for="(item,index) in groupList" :key="index" >
					<view class="msginfo_users_infoBox_img">
						<image :src="item.avatar" mode=""></image>
					</view>
					<view class="msginfo_users_infoBox_name">{{item.nick}}</view>
				</view>
				<!-- @tap="$api.navTo('/pages/chat_child/selectfriend/selectfriend?id='+groupID)" -->
				<view class="msginfo_users_infoBox flex-col" v-if="userInfo.uid==groupInfo.ownerID" >
					<view class="msginfo_users_infoBox_img add">
						<view>
							+
						</view>
					</view>
					<view class="msginfo_users_infoBox_name"> </view>
				</view>
			<!-- 	<view class="msginfo_users_infoBox flex-col">
					<view class="msginfo_users_infoBox_img subtract">
						<view>
							-
						</view>
					</view>
					<view class="msginfo_users_infoBox_name"> </view>
				</view> -->
			</view>
			<!-- <view class="msginfo_lookmore" @tap="$api.navTo('/pages/chat_child/selectfriend/selectfriend?id='+groupID+'&type=1')">
				查看更多群成员 
				<image src="../../../static/images/my/rightImg.png" mode=""></image>
			</view> -->
			<view class="msginfo_midinfo">
				<view class="msginfo_midinfo_groupname">
					<view class="msginfo_midinfo_groupname_left">群聊名称</view>
					<view class="msginfo_midinfo_groupname_right">
					   <input type="text" v-model="groupInfo.name" :disabled="userInfo.uid!=groupInfo.ownerID">
					<!-- <image src="../../../static/images/my/rightImg.png" mode=""></image> -->
					</view>
				</view>
				<view class="msginfo_midinfo_notice">
					<view class="msginfo_midinfo_notice_nameBox_left">群简介</view>
					<view class="msginfo_midinfo_notice_nameBox">
						
						<view class="msginfo_midinfo_notice_nameBox_right">
							<textarea  type="text"  v-model="groupInfo.introduction" placeholder="还没有群简介~" :disabled="userInfo.uid!=groupInfo.ownerID"></textarea>
						<!-- <image src="../../../static/images/my/rightImg.png" mode=""></image> -->
						</view>
					</view>
					<!-- <view class="msginfo_midinfo_notice_text">
						{{}}
					</view> -->
				</view>
			<!-- 	<view class="msginfo_midinfo_admin" @tap="$api.navTo('/pages/chat_child/selectfriend/selectfriend?id='+groupID)">
					<view class="msginfo_midinfo_admin_left">群管理</view>
					<view class="msginfo_midinfo_admin_right">
					<image src="../../../../static/images/my/rightImg.png" mode=""></image>
					</view>
				</view> -->
			</view>
			<!-- <view class="saveinfo_btn btn" @tap="setGroupInfo" v-if="userInfo.uid==groupInfo.ownerID">
				保存
			</view>
			<view class="msginfo_btn btn" @tap="quitGroup">
				退群
			</view> -->
		</view>
	</view>
</template>

<script>
	import {mapGetters} from 'vuex';
	export default {
		data() {
			return {
				groupID:'',
				groupList:[],
				groupInfo:{},
				userInfo:global.userInfo
			};
		},
		// ownerID
		onLoad(option) {
			this.groupID = option.id;
		},
		onShow() {
			console.log(global.userInfo)
			this.get_GroupList();
		},
		// computed:{
		// 	...mapGetters('overallData',{ 
		// 	         userInfo:'readUserInfo' 
		// 	      })
		// },
		methods:{
			/// 获取用户列表
			get_GroupList(){
				let thit = this;
			 var groupId = this.groupID.substr(5)
				let promise = uni.$TUIKit.getGroupProfile({ groupID:groupId});
				promise.then(function(imResponse) {
					console.log(imResponse);
					thit.groupInfo = imResponse.data.group;
					thit.getImgList(groupId);
				}).catch(function(imError) {
				  console.warn('getGroupProfile error:', imError); // 获取群详细资料失败的相关信息
				});
			},
			async getImgList(id){
				let thit = this;
				 var res = await uni.$TUIKit.getGroupMemberList({ groupID: id, count: 15, offset: 0 });
				if(res.code == 0){
					console.log(res.data)
					thit.groupList = res.data.memberList;
				}
				
			},
			
			setGroupInfo(){
				let thit = this;
				let promise = uni.$TUIKit.updateGroupProfile({
				  groupID: this.groupID.substr(5),
				  name: this.groupInfo.name, // 修改群名称
				  introduction: this.groupInfo.introduction// 修改群组维度自定义字段
				});
				promise.then(function(imResponse) {
					thit.$api.msg('修改成功');
					setTimeout(()=>{
						uni.navigateBack();
					},200)
				  console.log(imResponse.data.group) // 修改成功后的群组详细资料
				}).catch(function(imError) {
				  console.warn('updateGroupProfile error:', imError); // 修改群组资料失败的相关信息
				});
			},
			quitGroup(){
				let thit = this;
				uni.showModal({
					content:'确定退出该群组(退出后聊天记录将删除!)',
					success(res) {
						if(res.confirm){
							let promise = uni.$TUIKit.quitGroup(thit.groupID.substr(5));
							promise.then(function(imResponse) {
								thit.$api.msg('退出群组成功');
								setTimeout(()=>{
									uni.switchTab({
										url:'/pages/tabbar/chat/chat'
									})
								},400)
							  console.log(imResponse.data.groupID); // 退出成功的群 ID
							}).catch(function(imError){
								thit.$api.msg('退出群组失败');
							  console.warn('quitGroup error:', imError); // 退出群组失败的相关信息
							});
						}
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: rgba(247, 247, 247, 1);
	}
#msginfo{
	.msginfo{
		.msginfo_users{
			padding: 26rpx 14rpx;
			flex-wrap: wrap;
			background-color: #ffffff;
			.msginfo_users_infoBox{
				width: 100rpx;
				justify-content: center;
				margin: 20rpx 22rpx 24rpx;
				align-items: center;
				.msginfo_users_infoBox_img{
					display: flex;
					justify-content:center;
					width: 92rpx;
					height: 92rpx;
					align-items: center;
					border: 2rpx solid #CACACA;
					border-radius: 6rpx;
					image{
						width: 90rpx;
						height: 90rpx;
						border-radius: 10rpx;
					}
				}
				.add{
					font-size: 60rpx;
					color: #CACACA;
				}
				.subtract{
					font-size: 90rpx;
					color: #CACACA;
				}
				.msginfo_users_infoBox_name{
					width: 90rpx;
					height: 32rpx;
					margin-top: 14rpx;
					font-size: 24rpx;
					color: #666666;
					overflow:hidden;
					white-space:nowrap;
					text-overflow:ellipsis;
					text-overflow: ellipsis;/* IE/Safari */
					-ms-text-overflow: ellipsis;
				}
			}
		}
		.msginfo_lookmore{
			padding: 10rpx 0 30rpx;
			width: 100%;
			text-align: center;
			background-color: #ffffff;
			font-size: 26rpx;
			color: #666666;
			image{
				margin-left: 20rpx;
				width: 12rpx;
				height: 20rpx;
			}
		}
		.msginfo_midinfo{
			margin-top: 20rpx;
			background-color: #ffffff;
			padding: 0 30rpx;
			.msginfo_midinfo_groupname{
				height: 98rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 2rpx solid #EEEEEE;
				.msginfo_midinfo_groupname_left{
					font-size: 28rpx;
					color: #333333;
				}
				.msginfo_midinfo_groupname_right{
					display: flex;
					align-items: center;
					color: #666666;
					font-size: 28rpx;
					image{
						margin-left: 10rpx;
						width: 12rpx;
						height: 20rpx;
					}
				}
			}
			.msginfo_midinfo_notice{
				border-bottom: 2rpx solid #EEEEEE;
				padding-bottom: 20rpx;
				.msginfo_midinfo_notice_nameBox_left{
					font-size: 28rpx;
					color: #333333;
					margin-top: 20rpx;
				}
				.msginfo_midinfo_notice_nameBox{
					padding: 20rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					
					.msginfo_midinfo_notice_nameBox_right{
						flex:1;
						display: flex;
						align-items: center;
						color: #666666;
						font-size: 28rpx;
						image{
							margin-left: 10rpx;
							width: 12rpx;
							height: 20rpx;
						}
					}
				}
				
				.msginfo_midinfo_notice_text{
					font-size: 24rpx;
					color: #999999;
				}
			}
			.msginfo_midinfo_admin{
				height: 98rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 2rpx solid #EEEEEE;
				.msginfo_midinfo_admin_left{
					font-size: 28rpx;
					color: #333333;
				}
				.msginfo_midinfo_admin_right{
					color: #666666;
					font-size: 28rpx;
					image{
						margin-left: 10rpx;
						width: 12rpx;
						height: 20rpx;
					}
				}
			}
		}
		.msginfo_btn{
			margin: 30rpx 0 50rpx;
			width: 100%;
			height: 98rpx;
			background-color: #ffffff;
			color: #DA363C;
			text-align: center;
			line-height: 98rpx;
			font-size: 32rpx;
		}
		.saveinfo_btn{
			margin: 30rpx 0 20rpx;
			width: 100%;
			height: 98rpx;
			background-color: #12B8D7;
			color: #ffffff;
			text-align: center;
			line-height: 98rpx;
			font-size: 32rpx;
		}
	}
}
</style>
